package com.githan.bootsecurity.config;

import com.githan.bootsecurity.response.Result;
import com.githan.bootsecurity.response.ResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author https://github.com/Han56
 * @date 2021/4/11 19:06
 *
 */
@Component("myAccessDeniedHandler")
public class MyAccessDeniedHandler extends JSONAuthentication implements AccessDeniedHandler {

    /**
     * 权限不足处理器
     */
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        Result result=Result.error(ResultCode.NO_PERMISSION);
        this.WriteJSON(httpServletRequest,httpServletResponse,result);
    }
}
